<script setup lang="ts">
import {useLoaderStorage} from "@/store/modules/web3d/loader";
import {ThemeVO} from "@/api/pb/theme";
import {Group, Object3D} from "three";
import {useGLTF} from "@tresjs/cientos";
import {useEmitt} from "@/hooks/web/useEmitt";

const emitt = useEmitt()

const loader = useLoaderStorage()

const theme = inject<Ref<ThemeVO>>('theme')!
const contentGroup = inject<Group>('contentGroup')!

/**
 * 初始化
 */
const init = async () => {
  const url = theme!.value.modelUrl
  if (!url) return
  const { scene } = await useGLTF(url, {draco: true});

  const children = (scene.children[0] as Group).children
  contentGroup.add(...children)
  // children.forEach((child: Object3D) => {
  //   contentGroup.add(child)
  // })
  emitt.emit('changeStructTree')
}

/**
 * 统一顺序执行
 */
await loader.loader([
  init
])
</script>

<template>
  <div></div>
</template>

<style scoped lang="scss">

</style>
